package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.SyncRepayPlanDiffLogDao;
import com.fdb.efp.nls.service.domain.SyncRepayPlanDiffLog;
import com.fdb.efp.nls.service.facade.SyncRepayPlanDiffLogService;
import com.fdb.efp.nls.service.vo.SyncRepayPlanDiffLogVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * Service Impl: 还款计划差异表服务实现
 *
 * @author gcb
 * @date 2020-04-26
 */
@Service("syncRepayPlanDiffLogService")
public class SyncRepayPlanDiffLogServiceImpl implements SyncRepayPlanDiffLogService, FrameworkService {

    private static Logger logger = LoggerFactory.getLogger(SyncRepayPlanDiffLogServiceImpl.class);

    @Autowired
    private SyncRepayPlanDiffLogDao syncRepayPlanDiffLogDao;

    /**
     * 新增数据
     *
     * @param syncRepayPlanDiffLogVo
     * @return
     */
    @Override
    public int insert(SyncRepayPlanDiffLogVO syncRepayPlanDiffLogVo) {
        logger.debug("当前新增数据为:" + syncRepayPlanDiffLogVo.toString());
        int num = 0;
        try {
            SyncRepayPlanDiffLog syncRepayPlanDiffLog = new SyncRepayPlanDiffLog();
            beanCopy(syncRepayPlanDiffLogVo, syncRepayPlanDiffLog);
            num = syncRepayPlanDiffLogDao.insert(syncRepayPlanDiffLog);
        } catch (Exception e) {
            logger.error("新增数据发生异常!", e);
            num = -1;
        }
        logger.debug("当前新增数据条数为:" + num);
        return num;
    }

    /**
     * 根据主键删除信息
     *
     * @param syncRepayPlanDiffLogVo
     * @return
     */
    @Override
    public int deleteByPk(SyncRepayPlanDiffLogVO syncRepayPlanDiffLogVo) {
        logger.debug("当前删除数据条件为:" + syncRepayPlanDiffLogVo);
        int num = 0;
        try {
            SyncRepayPlanDiffLog syncRepayPlanDiffLog = new SyncRepayPlanDiffLog();
            beanCopy(syncRepayPlanDiffLogVo, syncRepayPlanDiffLog);
            num = syncRepayPlanDiffLogDao.deleteByPk(syncRepayPlanDiffLog);
        } catch (Exception e) {
            logger.error("删除数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncRepayPlanDiffLogVo + "删除的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键更新信息
     *
     * @param syncRepayPlanDiffLogVo
     * @return
     */
    @Override
    public int updateByPk(SyncRepayPlanDiffLogVO syncRepayPlanDiffLogVo) {
        logger.debug("当前修改数据为:" + syncRepayPlanDiffLogVo.toString());
        int num = 0;
        try {
            SyncRepayPlanDiffLog syncRepayPlanDiffLog = new SyncRepayPlanDiffLog();
            beanCopy(syncRepayPlanDiffLogVo, syncRepayPlanDiffLog);
            num = syncRepayPlanDiffLogDao.updateByPk(syncRepayPlanDiffLog);
        } catch (Exception e) {
            logger.error("修改数据发生异常!", e);
            num = -1;
        }
        logger.debug("根据条件:" + syncRepayPlanDiffLogVo + "修改的数据条数为" + num);
        return num;
    }

    /**
     * 根据主键查询详情
     *
     * @param inSyncRepayPlanDiffLogVo
     * @return
     */
    @Override
    public SyncRepayPlanDiffLogVO queryByPk(SyncRepayPlanDiffLogVO inSyncRepayPlanDiffLogVo) {
        logger.debug("当前查询参数信息为:" + inSyncRepayPlanDiffLogVo);
        try {
            SyncRepayPlanDiffLog querySyncRepayPlanDiffLog = new SyncRepayPlanDiffLog();
            beanCopy(inSyncRepayPlanDiffLogVo, querySyncRepayPlanDiffLog);
            SyncRepayPlanDiffLog queryRslSyncRepayPlanDiffLog = syncRepayPlanDiffLogDao.queryByPk(querySyncRepayPlanDiffLog);
            if (Objects.nonNull(queryRslSyncRepayPlanDiffLog)) {
                return beanCopy(queryRslSyncRepayPlanDiffLog, new SyncRepayPlanDiffLogVO());
            } else {
                logger.debug("当前查询结果为空!");
            }
        } catch (Exception e) {
            logger.error("查询数据发生异常!", e);
        }
        return null;
    }

    @Override
    public int batchInsert(List<SyncRepayPlanDiffLogVO> list) throws Exception {
        return this.syncRepayPlanDiffLogDao.batchInsert((List<SyncRepayPlanDiffLog>) beansCopy(list, SyncRepayPlanDiffLog.class));
    }
}
